/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jps.envs;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import jps.qres.AbstractQueryResult;
import jps.qres.BagResult;

/**
 *
 * @author calyJa
 */
public class ENVSStackFrame {

    public ENVSStackFrame(List<ENVSBinder> binders) {
        this.elements = binders;
    }

    public ENVSStackFrame() {
    }

    public void add(ENVSBinder binder) {
        elements.add(binder);
    }

    public BagResult get(String name) {
        List<AbstractQueryResult> bagElements = new ArrayList<AbstractQueryResult>();
        for (int i = 0; i < elements.size(); i++) {
            ENVSBinder binder = elements.get(i);
            if (binder.getName().equals(name)) {
                bagElements.add(binder.getValue());
            }
        }

        if (bagElements.isEmpty()) {
            return null;
        } else {
            return new BagResult(bagElements);
        }
    }

    @Override
    public String toString() {
        return "[" + elements + "]";
    }
    private List<ENVSBinder> elements = new LinkedList<ENVSBinder>();
}
